<template>
    <div>
        <Modal v-model="modal" class="modal-full" :title="actionModel.name" width="90%">
            <div v-if="modalShow">
                <grid-panel :data="listData" ref="list" v-if="isParse" :model="listModel" :hasCheck="true"></grid-panel>
            </div>
            <div slot="footer" class="button-panel-button">
                <i-button @click="close">返回</i-button>
                <i-button v-if="hasSubmit" @click="actionSubmit" :disabled="!enableSubmit" type="primary">确认</i-button>
            </div>
        </Modal>

    </div>
</template> 

<script>
import ModalBase from '../modalBase'
import $ from '@/common'
import GridPanel from '@/node/gridPanel'


export default {
    extends: ModalBase,
    props: {
    },
    data() {
        return {
            listModel: {},
            modelPath: '/service/{app}/dataset/model/{code}',
            isParse: false,
            hasSubmit: false,
            listData:[]
        }
    },
    created() { },
    methods: {
        load() {
            this.isParse = false
            var listPath = $.composePath(this.actionModel.path, this.$parent.actionData)
            var modelPath = $.composePath(this.modelPath, this.$parent.actionData)
            $.link(modelPath, null, {
                method: 'get'
            }).then(({ data }) => {
                this.listModel = {
                    path: listPath,
                    fields: data.fields
                }
                this.isParse = true
            })
        },
        //已弃用逻辑
        loadData() {
            var listPath = $.composePath(this.actionModel.path, this.$parent.actionData)
            if (this.$owner.model.slaves && this.$owner.model.slaves.length) {
                this.listModel = {
                    path: listPath,
                    fields: this.$owner.model.slaves[0].fields
                }
                this.isParse = true
            } else {
                $.link(listPath, null, {
                    param: this.$parent.actionData
                }).then((res) => {
                    var data = res.data
                    this.listModel = {
                        path: listPath,
                        fields: []
                    }
                    if (data.data && data.data.length) {
                        for (let i in data.data[0]) {
                            this.listModel.fields.push({
                                name: i,
                                code: i
                            })
                        }
                    }
                    this.isParse = true
                })
            }
        },
        actionSubmit() {

        }
    },
    components: {
        GridPanel
    }
}
</script>

<style lang="less">

</style>
